package Algorithm;

public class WordReverse_02 {
    public static String wordReverse_02(String iniString){
        //首先翻转整个字符串
        StringBuilder stringBuilder=new StringBuilder(iniString);
        String s1=stringBuilder.reverse().toString();
        //切割单词
        String[] words=s1.split("\\s");
        stringBuilder=new StringBuilder();
        for(int i=0;i<words.length;i++){
            StringBuilder stringBuilder2=new StringBuilder(words[i]);
            stringBuilder.append(stringBuilder2.reverse().toString()+" ");
        }
        return stringBuilder.deleteCharAt(stringBuilder.length()-1).toString();
    }
    public static void main(String[] args) {
        System.out.println(wordReverse_02("Mr John Smith"));
    }
}
